import { _decorator, Component, EventTouch, Label, Node } from 'cc';
import { Building } from '../entity/Buildings';
import { UIManager } from '../common/UIManager';
import { PrefabEnum } from '../common/PrefabEnum';
import { EventManager } from '../event/EventManager';
const { ccclass, property } = _decorator;

@ccclass('CatapultItem')
export class CatapultItem extends Component {

    @property(Label)
    buildingName:Label

    public _building:Building
    start() {
        this.node.on(Node.EventType.TOUCH_END, this.onTouchEnd, this)

        
    }

    protected onDisable(): void {
        EventManager.instance.off(EventManager.EventType.SelectBuilding, this.setData, this)
    }

    setData(building:Building){
        this._building = building
        this.buildingName.string = building.name

        EventManager.instance.off(EventManager.EventType.SelectBuilding, this.setData, this)
    }

    onTouchEnd(e:EventTouch){
        EventManager.instance.on(EventManager.EventType.SelectBuilding, this.setData, this)
        UIManager.instance.openUI(PrefabEnum.SelectBuilding)
    }
}


